export default function filterAsyncRoutes(routes: any, asyncRoutes: any) {
  return asyncRoutes.filter((item: any) => {
    if (routes.includes(item.name) || includeFather(routes, item)) {
      // console.log(1);
      if (item.children && item.children.length > 0) {
        item.children = filterAsyncRoutes(routes, item.children);
      }
      return true;
    }
  });
}

function includeFather(routes: any, father: any) {
  if (father.children && father.children.length > 0) {
    for (let i = 0; i < father.children.length; i++) {
      let child = father.children[i];
      if (routes.includes(child.name)) {
        return true;
      }
      if (child.children && child.children.length > 0) {
        if (includeFather(routes, child)) {
          return true;
        }
      }
    }
  }
  return false;
}
